package com.ecomm.util;

import org.apache.commons.logging.Log;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.hibernate.HibernateException;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * Created by IntelliJ IDEA.
 * User: Gavin
 * Date: 2007-1-30
 * Time: 13:36:58
 * To change this template use File | Settings | File Templates.
 */
public class SpringUtil {
    private static ApplicationContext ctx = null;

//    static{
//        ctx = new ClassPathXmlApplicationContext("/spring/*.xml");
//    }

    public static ApplicationContext getApplicationContext()
    {
        return ctx;
    }

    public static boolean containsBean(String bean){
        return ctx.containsBean(bean);
    }

    public static Object getBean(String name){
        return ctx.getBean(name);
    }

    public static Object getBean(String name, Class requiredType){
        return ctx.getBean(name,requiredType);
    }

    public static Connection getConnection() throws SQLException{
        DataSource dataSource = (DataSource)SpringUtil.getBean("dataSource");
        return dataSource.getConnection();
    }
}
